from feed_forward.backpropagation import Backpropagation
from feed_forward.feed_forward_network import FeedforwardNetwork
from feed_forward.feedforward_layer import FeedforwardLayer
from util.training_set import TrainingSet

__author__ = 'Douglas'

training_set = TrainingSet()

training_set.append([0.0, 0.0], [0.0])
training_set.append([1.0, 0.0], [0.0])
training_set.append([0.0, 1.0], [0.0])
training_set.append([1.0, 1.0], [1.0])

network = FeedforwardNetwork()

network.add_layer(FeedforwardLayer(2))
network.add_layer(FeedforwardLayer(1))

network.reset()

train = Backpropagation(network, training_set, 0.7, 0.9)

for epoch in range(1, 5001):
    train.iteration()
    print("Epoch #", epoch, "Error:", train.error)

    if train.error <= 0.001:
        break

print("Result:")

for row in training_set:
    actual = network.compute_outputs(row.input_pattern)
    print(row.input_pattern, "actual=", actual[0], "ideal=", row.ideal_output)